<?php

use yii\helpers\Html;
use yii\grid\GridView;

use app\models\U;
use app\models\MUser;


/* @var $this yii\web\View */
/* @var $searchModel app\models\MUserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '用户管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="muser-index">

    <h4><?= Html::encode($this->title) ?></h4>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>


    <p>
        <?php echo Html::a('下载 <i class="glyphicon glyphicon-arrow-down"></i>', U::current(['download' => 1]), ['class' => 'btn btn-success', 'data-pjax' => '0',]); ?>
        &nbsp;&nbsp;
        <?= Html::a('新建用户', ['create'], ['class' => 'btn btn-success']) ?>
    </p>


    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'showOnEmpty'=>false,
        'layout'=>"{items}{pager}\n{summary}",
        'tableOptions' =>['class' => 'table table-striped'],
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],

           // 'id',
            'username',
            'mobile',
            //'auth_key',
            //'password_hash',
            // 'password_reset_token',
            'email:email',
            // 'status',
            //'created_at',
            [
                'attribute' => 'created_at',
                'label' => '注册时间',
                'value' => function($data) {
                    return date('Y-m-d H:i:s',$data->created_at); 
                }
            ],

            // 'updated_at',
            //'role',
            [
                'attribute' => 'role',
                'label' => '角色',
                'value'=>function ($model, $key, $index, $column) {
                    return MUser::getRoleOption($model->role);
                },
                'filter'=> MUser::getRoleOption(),
            ],

            //'usertype',
            [
                'attribute' => 'usertype',
                'label' => '用户类型',
                'value'=>function ($model, $key, $index, $column) {
                    return MUser::getUserTypeOption($model->usertype);
                },
                'filter'=> MUser::getUserTypeOption(),
            ],


            [
                'attribute' => 'seller_level',
                'label' => '卖家等级',
                'value'=>function ($model, $key, $index, $column) {
                    return MUser::getSellerLevelOption($model->seller_level);
                },
                'filter'=> MUser::getSellerLevelOption(),
            ],

            [
                'attribute' => 'buyer_level',
                'label' => '买家等级',
                'value'=>function ($model, $key, $index, $column) {
                    return MUser::getBuyerLevelOption($model->buyer_level);
                },
                'filter'=> MUser::getBuyerLevelOption(),
            ],

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

</div>
